package com.huslee.shark.log.log4j2.event;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.ThrowableProxy;
import org.apache.logging.log4j.core.time.Instant;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.util.ReadOnlyStringMap;
import org.apache.skywalking.apm.toolkit.trace.TraceContext;

import java.util.Map;

/**
 * @author: zhanglin574@xdf.cn
 * @date: 2021/8/10
 * @description:
 */
public class ElkLog4jEvent implements LogEvent {

    @JsonIgnore
    private final LogEvent event;

    private String skyWalkingDynamicField;

    private String projectName;

    public ElkLog4jEvent(LogEvent event) {
        skyWalkingDynamicField = TraceContext.traceId();
        this.event = event;
    }

    @Override
    public LogEvent toImmutable() {
        return event.toImmutable();
    }

    @Override
    public Map<String, String> getContextMap() {
        return event.getContextMap();
    }

    @Override
    public ReadOnlyStringMap getContextData() {
        return event.getContextData();
    }

    @Override
    public ThreadContext.ContextStack getContextStack() {
        return event.getContextStack();
    }

    @Override
    public String getLoggerFqcn() {
        return event.getLoggerFqcn();
    }

    @Override
    public Level getLevel() {
        return event.getLevel();
    }

    @Override
    public String getLoggerName() {
        return event.getLoggerName();
    }

    @Override
    @JsonIgnore
    public Marker getMarker() {
        return event.getMarker();
    }

    @Override
    @JsonProperty("m_content")
    public Message getMessage() {
        return event.getMessage();
    }

    @Override
    public long getTimeMillis() {
        return event.getTimeMillis();
    }

    @Override
    @JsonIgnore
    public Instant getInstant() {
        return event.getInstant();
    }

    @Override
    @JsonIgnore
    public StackTraceElement getSource() {
        return event.getSource();
    }

    @Override
    public String getThreadName() {
        return event.getThreadName();
    }

    @Override
    @JsonIgnore
    public long getThreadId() {
        return event.getThreadId();
    }

    @Override
    @JsonIgnore
    public int getThreadPriority() {
        return event.getThreadPriority();
    }

    @Override
    @JsonIgnore
    public Throwable getThrown() {
        return event.getThrown();
    }

    @Override
    public ThrowableProxy getThrownProxy() {
        return event.getThrownProxy();
    }

    @Override
    @JsonIgnore
    public boolean isEndOfBatch() {
        return event.isEndOfBatch();
    }

    @Override
    @JsonIgnore
    public boolean isIncludeLocation() {
        return event.isIncludeLocation();
    }

    @Override
    public void setEndOfBatch(boolean endOfBatch) {

    }

    @Override
    public void setIncludeLocation(boolean locationRequired) {

    }

    @Override
    @JsonIgnore
    public long getNanoTime() {
        return event.getNanoTime();
    }

    public String getSkyWalkingDynamicField(){
        return skyWalkingDynamicField;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

}
